﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;

namespace ClassLibrary
{
    public static class ClsImage
    {
        /// <summary>
        /// 將圖片轉為二進位資料
        /// </summary>
        public static byte[] imgToBinary(Image image)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] binaryImage = ms.ToArray();
                return binaryImage;
            }
        }

        /// <summary>
        /// 將二進位資料轉為圖片
        /// </summary>
        public static Image binaryToImage(byte[] binaryImage)
        {
            using (MemoryStream ms = new MemoryStream(binaryImage))
            {
                Image image = Image.FromStream(ms);
                return image;
            }
        }
    }
}
